package com.hz.edu.mapper;

import com.hz.edu.model.entity.UserCourseEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserCourseMapper {

    @Insert("insert into user_courses values (null, #{course_name}, #{course_code}, #{student_user_id}, #{teacher_user_id}, #{student_realname}, #{teacher_realname}, #{user_score}, #{course_id})")
    int addUserCourse(UserCourseEntity userCourseEntity);

    @Select("select * from user_courses where course_id = #{courseId} and student_user_id = #{studentId}")
    UserCourseEntity selectByCourseAndStudentId(@Param("courseId") Integer courseId, @Param("studentId") Integer studentId);

    @Delete("delete from user_courses where course_id = #{courseId} and student_user_id = #{studentId};")
    int deleteUserCourse(@Param("courseId") Integer courseId, @Param("studentId") Integer studentId);

    @Update("update user_courses set user_score = #{score} where student_user_id = #{studentId} and course_id = #{courseId}")
    int updateScore(Integer courseId, Integer studentId, Integer score);

    @Select("select * from user_courses where student_user_id = #{studentId}")
    List<UserCourseEntity> selectedCoursesOfStudentId(@Param("studentId") Integer studentId);

}
